<template>
  <div class="add-order">
    <NavBar title="新增订单"></NavBar>
    <van-field
      v-model="formData.phone"
      label="手机号"
      placeholder="请输入用户名"
    />
    <van-field
      v-model="formData.serial_number"
      label="产品序列号"
      placeholder="请输入用户名"
    />
    <van-field
      v-model="formData.express_number"
      label="物流单号"
      placeholder="请输入用户名"
    />

    <van-button type="primary" block @click="submit">确定</van-button>
  </div>
</template>

<script>
import NavBar from "../components/NavBar";
export default {
  data() {
    return {
      formData: {
        phone: "",
        serial_number: "",
        express_number: "",
      },
    };
  },
  methods: {
    submit() {
      if (
        !Object.keys(this.formData).every(
          (item) => this.formData[item].length > 0
        )
      ) {
        this.$toast.fail("信息填写错误，请重新检查后提交");
      } else {
        this.$axios.post("order/order", this.formData).then((res) => {
          if (res.data.code == 200) {
            this.$router.go(-1);
            this.$toast.success(res.data.msg);
          } else {
            this.$toast.fail("添加失败");
          }
        });
      }
    },
  },
  components: {
    NavBar,
  },
};
</script>

<style scoped lang="scss">
.add-order {
  background-color: #f0f0f0;
  padding-top: 1.1728rem;
  padding-bottom: 1.4928rem;
}
</style>